import React, { Component } from 'react'
import { userService } from '../../service'


export default class UserInfo extends Component {
    
    constructor (props) {
        super(props)
        this.go = this.go.bind(this);//go方法中引用this(this重新指向)
        this.selById = this.selById.bind(this);
    }

    componentDidMount(){
        const pp =  this.refs.upd;
        console.log(this);
        console.log(pp.getAttribute("data-name"));
        
    }

    go(ss){
        var index=ss.target.getAttribute("data-name");
        console.log(index);
        //userAction.selUserAll
        console.log(this);
        userService.selUserAll(null,this.props.actions.selUser);
    }

    selById(e){
        console.log("---------------------------按id查------------------------")
        var id=e.target.getAttribute("data-id");
        console.log({id:id});
        userService.selUserById({id:id},this.props.actions.selUserById);
    }


    render() {

        const {id,name,pwd} = this.props.user;
        console.log("++++++++++++++UserInfo+++++++++++++++++");
        console.log(this);
        return (
            <tr>
                <td>{id}</td>
                <td>{name}</td>
                <td>{pwd}</td>
                <td><a data-id={id} ref="upd" onClick={this.selById}>修改</a></td>
                <td><a data-name={name} ref="del" onClick={this.go}>删除</a></td>
            </tr>
        )
    }

}
